package com.itheima.exception;

import com.itheima.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice// 注解@RestControllerAdvice表示这是一个控制器增强器，可以捕获控制器抛出的异常并返回统一的响应
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result doException(Exception e) {
        log.error(e.getMessage());
        return Result.error("出错了，请联系管理员！");
    }
    @ExceptionHandler
    public Result handleBusinessException(BusinessException e){
        log.error("程序运行出错啦 .... ", e);
        return Result.error(e.getMessage());
    }
}
